package cn.stylefeng.guns.sys.modular.system.db6.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.db6.entity.SysDict;
import cn.stylefeng.guns.sys.modular.system.db6.entity.SysDictType;
import cn.stylefeng.guns.sys.modular.system.db6.mapper.SysDictTypeMapper;
import cn.stylefeng.guns.sys.modular.system.db6.model.params.SysDictTypeParam;
import cn.stylefeng.guns.sys.modular.system.db6.model.result.SysDictTypeResult;
import  cn.stylefeng.guns.sys.modular.system.db6.service.SysDictTypeService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 字典类型表 服务实现类
 * </p>
 *
 * @author wjk
 * @since 2021-09-30
 */
@Service
public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictType> implements SysDictTypeService {

    @Override
    public void add(SysDictTypeParam param){
        SysDictType entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(SysDictTypeParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(SysDictTypeParam param){
        SysDictType oldEntity = getOldEntity(param);
        SysDictType newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public SysDictTypeResult findBySpec(SysDictTypeParam param){
        return null;
    }

    @Override
    public List<SysDictTypeResult> findListBySpec(SysDictTypeParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(SysDictTypeParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(SysDictTypeParam param){
        return param.getDictTypeId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private SysDictType getOldEntity(SysDictTypeParam param) {
        return this.getById(getKey(param));
    }

    private SysDictType getEntity(SysDictTypeParam param) {
        SysDictType entity = new SysDictType();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
